﻿using System;
using System.Drawing;
using XnaRectangle = Microsoft.Xna.Framework.Rectangle;
using XnaPoint = Microsoft.Xna.Framework.Point;

namespace Map_Creator
{
    public static class MathEx
    {
        public static int Clamp(int value, int min, int max)
        {
            if (value < min)
                return min;
            if (value > max)
                return max;
            return value;
        }

        public static Rectangle JoinRectangles(Rectangle a, Rectangle b)
        {
            var left = Math.Min(a.Left, b.Left);
            var top = Math.Min(a.Top, b.Top);
            var right = Math.Max(a.Right, b.Right);
            var buttom = Math.Max(a.Bottom, b.Bottom);
            return Rectangle.FromLTRB(left, top, right, buttom);
        }

        public static XnaRectangle JoinRectangles(XnaRectangle a, XnaRectangle b)
        {
            var left = Math.Min(a.Left, b.Left);
            var top = Math.Min(a.Top, b.Top);
            var right = Math.Max(a.Right, b.Right);
            var buttom = Math.Max(a.Bottom, b.Bottom);
            return new XnaRectangle(left, top, right, buttom);
        }

        public static Rectangle ConvertToSystemRect(XnaRectangle rectangle)
        {
            return new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
        }
        public static Point ConvertToSystemPoint(XnaPoint point)
        {
            return new Point(point.X, point.Y);
        }
    }
}